﻿using DefenseQuestion.Application.QuestionBankApplication;
using DefenseQuestion.Application.QuestionBankApplication.Dto;
using DefenseQuestion.Application.UserApplication;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Documents;
using System.Numerics;
using System.Threading.Tasks;

namespace DefenseQuestion.WebAPI.Controllers
{
    /// <summary>
    /// 题库管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class QuestionController : ControllerBase
    {
       /// <summary>
       /// 构造函数
       /// </summary>
       /// <param name="question"></param>
        public QuestionController(IQuestionService question)
        {
            Question = question;
        }

        public IQuestionService Question { get; }
        /// <summary>
        /// 添加题库
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddQusetionAsync(CreateandUpdateQuestionDto dto)
        {
            var list =await Question.AddQusetionAsync(dto);
            return Ok(list);
        }
        /// <summary>
        /// 修改题库
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdateQuestionAsync(CreateandUpdateQuestionDto dto)
        {
            var list=await Question.UpdateQusetionAsync(dto);
            return Ok(list);
        }
        /// <summary>
        /// 删除题库
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DeleteQuestionAsync(int id)
        {
            var list=await Question.DeleteQusetionAsync(id);
            return Ok(list);
        }
        /// <summary>
        /// 反填题库
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult FindQuestion(int id)
        {
            var list =  Question.FindQusetion(id);
            return Ok(list);
        }
        /// <summary>
        /// 分页显示题库
        /// </summary>
        /// <param name="TechTypeId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetQusetionsAsync(int TechTypeId, int pageIndex, int pageSize)
        {
            var list=Question.GetQusetionsAsync(TechTypeId, pageIndex, pageSize);
            return Ok(list);
        }
        /// <summary>
        /// 答题类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetQuestionTypeDto()
        {
            var list= Question.GetQuestionTypeDto();
            return Ok(list);
        }
        /// <summary>
        /// 技术分类表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetTechType()
        {
            var list=Question.GetTechType();
            return Ok(list);
        }
    }
}
